const { fork } = require("child_process");

//这个可以在两个进程之间实现通信

let childProcess = fork("fork_child.js")
let index = 0;
// console.log(childProcess);

let intervalId = setInterval(() => {
    childProcess.send("this is a message from parent process " + index);
    index++;
    if(index == 10) {
        clearInterval(intervalId);
    }
} , 1000)

childProcess.on("message" , (msg) => {
    console.log(msg);    
})

// console.log(Object.prototype.toString.call(childProcess));